<?php
$bartuserServices = new BartuserService();
switch ($action) {
	case "add":
		if($permit == true)
		{
			$data = array();
			foreach ($_POST as $key => $value) {
				$data[$key] = $value;
			}
			$bartUserDomain = new BartuserDomain($data);			
			$userDomain = new UserDomain($data);
			$bArtUser = new BArtUser($bartUserDomain);
			$bArtUser->setUserDomain($userDomain);
			$bartuserServices->createBArtUser($context, $result, $bArtUser);
			if($result->isFailed())
				echo "<script>alert('".$result->getMessage()."');window.location='index.php?func=user&opt=list';</script>";
			else
				header("Location:index.php?func=user&opt=list");
		}
		else
			header("Location:index.php?func=dash");
	break;
	
	case "delete":
		if($permit == true)
		{
			if(isset($_GET['id']))
			{
				$bArtUser = $bartuserServices->getBArtUserByOid($context, $result, $_GET['id']);
				$bartuserServices->deleteBArtUser($context, $result, $bArtUser);
				header("Location:index.php?func=user&opt=list");
			}
			else 
			{
				echo "case: ".$type." action : delete  ";
			}
		}
		else
			header("Location:index.php?func=dash");
	break;
	
	case "edit":
		if($permit == true)
		{
			$data = array();
			foreach ($_POST as $key => $value) {
				$data[$key] = $value;
			}							
			$bartuserDomain = new BartuserDomain($data);
			$userDomain = new UserDomain($data);
			$userDomain->setID($data['id']);
			$bArtUser = new BArtUser($bartuserDomain);
			$bArtUser->setUserDomain($userDomain);
			$bartuserServices->updateBArtUser($context, $result, $bArtUser);							
			header("Location:index.php?func=user&opt=list");
		}
		else
			header("Location:index.php?func=dash");
	break;
	
	default:
		echo "khong co tinh nang nay";
	break;
}
?>				